<?php
/************************************** Theme Widgets **************************************/

// WIDGET SEARCH
class SOFA_Widget_Search extends WP_Widget {

	function SOFA_Widget_Search() {
		$widget_ops = array( 'classname' => 'widget_sofa_search', 'description' => __( 'Add Search form.' ) );
		$this->WP_Widget( 'sofa_search', 'SOFA Search', $widget_ops );
	}

	function widget( $args, $instance ) {
		
		extract( $args, EXTR_SKIP );
		
		echo $before_widget;
		
		?>
		<form class="searchform textright" method="get" action="<?php echo home_url(); ?>">
			<div id="sfdiv">
			<input 
			class="search" 
			name="s" 
			type="text" 
			id="wpsrch" 
			onfocus="if( this.value == '<?php _e( "Search...", "sofa_suppastore" ); ?>' ) this.value = '';" 
			onblur="if( this.value == '' ) this.value = '<?php _e( "Search...", "sofa_suppastore" ); ?>';" 
			value="<?php _e( "Search...", "sofa_suppastore" ); ?>" 
			tabindex="1" />
			<input type="submit" class="search-btn" name="submit" value="" />
			</div>
		</form>
        <?php
		
		echo $after_widget;

	}

	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_search_p' ]     = $new_instance[ 's_search_p' ];
		return $instance;
	}

}
register_widget( 'SOFA_Widget_Search' );

// WIDGET ARBITRARY TEXT
class SOFA_Widget_Text extends WP_Widget {

	function SOFA_Widget_Text() {
		$widget_ops = array( 'classname' => 'widget_sofa_text', 'description' => __( 'Suppastore arbitrary text or HTML' ) );
		$control_ops = array( 'width' => 400, 'height' => 350 );
		$this->WP_Widget( 'sofa_text', 'SOFA Arbitrary Text/HTML', $widget_ops, $control_ops );
	}

	function widget( $args, $instance ) {
		
		extract( $args, EXTR_SKIP );
		
		$s_text_title = empty( $instance[ 's_text_title' ] ) ? '' : apply_filters( 'widget_s_text_title', $instance[ 's_text_title' ] ); // title
		$s_text_text  = empty( $instance[ 's_text_text' ] ) ? '' : apply_filters( 'widget_s_text_text', $instance[ 's_text_text' ] ); // content
		$s_text_p     = empty( $instance[ 's_text_p' ] ) ? 0 : apply_filters( 'widget_s_text_p', $instance[ 's_text_p' ] ); // auto paragraphs
		$s_text_shdw  = empty( $instance[ 's_text_shdw' ] ) ? 0 : apply_filters( 'widget_s_text_shdw', $instance[ 's_text_shdw' ] ); // image shadows
		
		echo $before_widget;
		
		if( $s_text_title != '' ) {
			echo $before_title . $s_text_title . $after_title;
			echo '<span class="underline clearfix">&nbsp;</span>';
		};
		
		if( $s_text_shdw ) echo '<div class="sidenews castshadow clearfix">';
		else echo '<div class="sidenews clearfix">';
		if( $s_text_p ) echo do_shortcode( wpautop( $s_text_text ) );
		else echo $s_text_text;
		echo '</div>';
		
		echo $after_widget;

	}

	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_text_title' ] = strip_tags( $new_instance[ 's_text_title' ] );
		$instance[ 's_text_text' ]  = $new_instance[ 's_text_text' ];
		$instance[ 's_text_p' ]     = $new_instance[ 's_text_p' ];
		$instance[ 's_text_shdw' ]  = $new_instance[ 's_text_shdw' ];
		return $instance;
	}

	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_text_title' => '', 's_text_text' => '', 's_text_p' => '', 's_text_shdw' => '' ) );
		$s_text_title = strip_tags( $instance[ 's_text_title' ] );
		$s_text_text  = $instance[ 's_text_text' ];
		$s_text_p     = $instance[ 's_text_p' ];
		$s_text_shdw  = $instance[ 's_text_shdw' ];
?>

<p>
<label for="<?php echo $this->get_field_id( 's_text_title' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_text_title' ); ?>" name="<?php echo $this->get_field_name( 's_text_title' ); ?>" type="text" value="<?php echo esc_attr( $s_text_title ); ?>" />
</label>
</p>

<label for="<?php echo $this->get_field_id( 's_text_text' ); ?>">
Text (HTML is OK):
</label>
<textarea class="widefat" rows="16" cols="50" id="<?php echo $this->get_field_id( 's_text_text' ); ?>" name="<?php echo $this->get_field_name( 's_text_text' ); ?>" type="text" value="<?php echo esc_attr( $s_text_text ); ?>"><?php echo $s_text_text; ?></textarea>

<p>
<label for="<?php echo $this->get_field_id( 's_text_p' ); ?>">
Automatically add paragraphs? 
</label>
<select class="widefat" id="<?php echo $this->get_field_id( 's_text_p' ); ?>" name="<?php echo $this->get_field_name( 's_text_p' ); ?>">
	<?php if( $s_text_p == 1 ) { ?>
    <option value="1" selected="selected"> - YES - </option>
    <option value="0"> - NO - </option>
    <?php
    } else if( $s_text_p == 0 ) {
    ?>
    <option value="1"> - YES - </option>
    <option value="0" selected="selected"> - NO - </option>
    <?php
    } else {
    ?>
    <option value="1" selected="selected"> - YES - </option>
    <option value="0"> - NO - </option>
    <?php
    }
    ?>
</select>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_text_shdw' ); ?>">
Add shadow below image(s)? 
</label>
<select class="widefat" id="<?php echo $this->get_field_id( 's_text_shdw' ); ?>" name="<?php echo $this->get_field_name( 's_text_shdw' ); ?>">
	<?php if( $s_text_shdw == 1 ) { ?>
    <option value="1" selected="selected"> - YES - </option>
    <option value="0"> - NO - </option>
    <?php
    } else if( $s_text_shdw == 0 ) {
    ?>
    <option value="1"> - YES - </option>
    <option value="0" selected="selected"> - NO - </option>
    <?php
    } else {
    ?>
    <option value="1" selected="selected"> - YES - </option>
    <option value="0"> - NO - </option>
    <?php
    }
    ?>
</select>
</p>
            
<?php
	}
}
register_widget( 'SOFA_Widget_Text' );

// WIDGET NAVIGATION
 class SOFA_WidgetMenu extends WP_Widget {

	function SOFA_WidgetMenu() {
		$widget_ops = array( 'classname' => 'widget_sofa_menus', 'description' => 'Add Widget Menu to any widget ready sidebar or footer.' );
		$this->WP_Widget( 'sofa_menus', 'SOFA Widget Menu', $widget_ops );
	}
	
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
		
		$s_menus_title = empty( $instance[ 's_menus_title' ] ) ? '' : apply_filters( 'widget_s_menus_title', $instance[ 's_menus_title' ] );
		$s_menus_usel  = empty( $instance[ 's_menus_usel' ] ) ? '' : apply_filters( 'widget_s_menus_usel', $instance[ 's_menus_usel' ] );
		$s_menus_depth = empty( $instance[ 's_menus_depth' ] ) ? 0 : apply_filters( 'widget_s_menus_depth', $instance[ 's_menus_depth' ] );
		
		echo $before_widget;
		
		if( $s_menus_title != '' ) {
			echo $before_title . $s_menus_title . $after_title;
			echo '<span class="underline clearfix">&nbsp;</span>';
		};
		
		$menu_object = wp_get_nav_menu_object( $s_menus_usel );
		$sel_menu_id = $menu_object->term_id;
		if( $sel_menu_id > 0 ) {
			$menu_defaults_widget = array(
			  'menu'            => $sel_menu_id, 
			  'container'       => '', 
			  'container_class' => '', 
			  'container_id'    => '', 
			  'menu_class'      => 'sidenavig', 
			  'menu_id'         => '',
			  'echo'            => true,
			  'fallback_cb'     => '',
			  'before'          => '',
			  'after'           => '',
			  'link_before'     => '',
			  'link_after'      => '',
			  'depth'           => $s_menus_depth,
			  'walker'          => '',
			  'theme_location'  => '' );
			 
			wp_nav_menu( $menu_defaults_widget ); 
		}
		
		echo $after_widget;
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_menus_title' ] = strip_tags( stripslashes( $new_instance[ 's_menus_title' ] ) );
		$instance[ 's_menus_usel' ]  = $new_instance[ 's_menus_usel' ];
		$instance[ 's_menus_depth' ] = ( intval( $new_instance[ 's_menus_depth' ] ) < 0 ) ? 0 : intval( $new_instance[ 's_menus_depth' ] );
		return $instance;
	}
	
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_menus_title' => '', 's_menus_usel' => '' ) );
		$s_menus_title = strip_tags( stripslashes( $instance[ 's_menus_title' ] ) );
		$s_menus_usel  = $instance[ 's_menus_usel' ];
		$s_menus_depth = intval( $instance[ 's_menus_depth' ] );
		$avail_menus   = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
		if( !$avail_menus ) {
			echo '<p class="smallfoot">'. sprintf( __( "No menus have been created yet. <a href='%s'>Create some</a>.", "sofa_suppastore" ), admin_url( 'nav-menus.php' ) ) . '</p>';
			return;
		}
?>

        <p>
        <label for="<?php echo $this->get_field_id( 's_menus_title' ); ?>">
        Title: 
        <input class="widefat" id="<?php echo $this->get_field_id( 's_menus_title' ); ?>" name="<?php echo $this->get_field_name( 's_menus_title' ); ?>" type="text" value="<?php echo esc_attr( $s_menus_title ); ?>" />
        </label>
        </p>
		<p>
		<label for="<?php echo $this->get_field_id( 's_menus_usel' ); ?>">Select Widget Menu:</label>
		<select id="<?php echo $this->get_field_id( 's_menus_usel' ); ?>" name="<?php echo $this->get_field_name( 's_menus_usel' ); ?>">
		<?php
		foreach( $avail_menus as $mnu ) {
			if( $mnu->term_id == $s_menus_usel ) echo '<option selected="selected" value="'. $mnu->term_id .'">'. $mnu->name .'</option>';
			else echo '<option value="'. $mnu->term_id .'">'. $mnu->name .'</option>';
		}
		?>
		</select>
		</p>
        <p>
        <label for="<?php echo $this->get_field_id( 's_menus_depth' ); ?>">
        How many levels of the hierarchy are to be included? 0 means all!
        <input id="<?php echo $this->get_field_id( 's_menus_depth' ); ?>" name="<?php echo $this->get_field_name( 's_menus_depth' ); ?>" type="text" size="3" value="<?php echo esc_attr( $s_menus_depth ); ?>" />
        </label>
        </p>
            
<?php
	}
}
register_widget( 'SOFA_WidgetMenu' );

// Advertising 125x125px
class SOFA_Adverts extends WP_Widget {
	function SOFA_Adverts() {
		$widget_ops = array( 'classname' => 'widget_sofa_adverts', 'description' => 'Add 125x125px advertising units.' );
		$control_ops = array( 'width' => 640, 'height' => 400 );
		$this->WP_Widget( 'sofa_adverts', 'SOFA Adverts', $widget_ops, $control_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
		
		$s_adverts_title = empty( $instance[ 's_adverts_title' ] ) ? __( "Advertising", "sofa_suppastore" ) : apply_filters( 'widget_s_adverts_title', $instance[ 's_adverts_title' ] );
		$s_adverts_code  = empty( $instance[ 's_adverts_code' ] ) ? '' : apply_filters( 'widget_s_adverts_code', $instance[ 's_adverts_code' ] );
		
		echo $before_widget;
		
		if( $s_adverts_title != '' ) {
			echo $before_title . $s_adverts_title . $after_title;
			echo '<span class="underline clearfix">&nbsp;</span>';
		};
		
		echo '<div class="sidenews adverts clearfix">';
		echo $s_adverts_code;
		echo '</div>';
		
		echo $after_widget;
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_adverts_title' ] = strip_tags( $new_instance[ 's_adverts_title' ] );
		$instance[ 's_adverts_code' ]  = $new_instance[ 's_adverts_code' ];
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_adverts_title' => '', 's_adverts_code' => '' ) );
		$s_adverts_title = strip_tags( $instance[ 's_adverts_title' ] );
		$s_adverts_code  = $instance[ 's_adverts_code' ];
?>

<p>
<label for="<?php echo $this->get_field_id( 's_adverts_title' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_adverts_title' ); ?>" name="<?php echo $this->get_field_name( 's_adverts_title' ); ?>" type="text" value="<?php echo esc_attr( $s_adverts_title ); ?>" />
</label>
</p>

<label for="<?php echo $this->get_field_id( 's_adverts_code' ); ?>">
Advertising code (HTML):
</label>
<textarea class="widefat" rows="16" cols="50" id="<?php echo $this->get_field_id( 's_adverts_code' ); ?>" name="<?php echo $this->get_field_name( 's_adverts_code' ); ?>" type="text" value="<?php echo esc_attr( $s_adverts_code ); ?>"><?php echo $s_adverts_code; ?></textarea>
            
<?php
	}
}
register_widget( 'SOFA_Adverts' );

// TWITTER 
class SOFA_Twitter extends WP_Widget {
	function SOFA_Twitter() {
		$widget_ops = array( 'classname' => 'widget_sofa_twitter', 'description' => 'Display Twitter Twitts for desired user.' );
		$this->WP_Widget( 'sofa_twitter', 'SOFA Twitter', $widget_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
		
		$s_twitter_title = empty( $instance[ 's_twitter_title' ] ) ? '' : apply_filters( 'widget_s_twitter_title', $instance[ 's_twitter_title' ] );
		$s_twitter_user  = empty( $instance[ 's_twitter_user' ] ) ? 'dameer' : apply_filters( 'widget_s_twitter_user', $instance[ 's_twitter_user' ] );
		$s_twitts_number = empty( $instance[ 's_twitts_number' ] ) ? 'dameer' : apply_filters( 'widget_s_twitts_number', $instance[ 's_twitts_number' ] );
		
		echo $before_widget;

		if( $s_twitter_title != '' ) {
			echo $before_title . $s_twitter_title . $after_title;
			echo '<span class="underline clearfix">&nbsp;</span>';
		};
		
		
		echo '<div class="sidenews clearfix">';
		echo '<ol id="twitter_update_list"><li>&nbsp;</li></ol>';
        echo '<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script>';
        echo '<script type="text/javascript" src="http://twitter.com/statuses/user_timeline/' . $s_twitter_user . '.json?callback=twitterCallback2&amp;count=' . $s_twitts_number . '"></script>';
		echo '</div>';
		
		echo $after_widget;
		
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_twitter_title' ] = strip_tags( $new_instance[ 's_twitter_title' ] );
		$instance[ 's_twitter_user' ]  = strip_tags( $new_instance[ 's_twitter_user' ] );
		$instance[ 's_twitts_number' ] = strip_tags( $new_instance[ 's_twitts_number' ] );
 
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_twitter_title' => '', 's_twitter_user' => '', 's_twitts_number' => '' ) );
		$s_twitter_title = strip_tags( $instance[ 's_twitter_title' ] );
		$s_twitter_user  = strip_tags( $instance[ 's_twitter_user' ] );
		$s_twitts_number = strip_tags( $instance[ 's_twitts_number' ] );
?>

<p>
<label for="<?php echo $this->get_field_id( 's_twitter_title' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_twitter_title' ); ?>" name="<?php echo $this->get_field_name( 's_twitter_title' ); ?>" type="text" value="<?php echo esc_attr( $s_twitter_title ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_twitter_user' ); ?>">
Twitter Username: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_twitter_user' ); ?>" name="<?php echo $this->get_field_name( 's_twitter_user' ); ?>" type="text" value="<?php echo esc_attr( $s_twitter_user ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_twitts_number' ); ?>">
Number of Twitts to show: 
<input id="<?php echo $this->get_field_id( 's_twitts_number' ); ?>" name="<?php echo $this->get_field_name( 's_twitts_number' ); ?>" type="text" size="3" value="<?php echo esc_attr( $s_twitts_number ); ?>" />
</label>
</p>
            
<?php
	}
}
register_widget( 'SOFA_Twitter' );

// FLICKR
class SOFA_Flickr extends WP_Widget {
	function SOFA_Flickr() {
		$widget_ops = array( 'classname' => 'widget_sofa_flickr', 'description' => 'Display Flickr photos from desired user or by tag(s).' );
		$this->WP_Widget( 'sofa_flickr', 'SOFA Flickr', $widget_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
 
		echo $before_widget;
		
		$s_flickr_title  = empty( $instance[ 's_flickr_title' ] ) ? '' : apply_filters( 'widget_s_flickr_title', $instance[ 's_flickr_title' ] );
		$s_flickr_choice = empty( $instance[ 's_flickr_choice' ] ) ? '14897087@N04' : apply_filters( 'widget_s_flickr_choice', $instance[ 's_flickr_choice' ] );
		$s_flickr_noi    = empty( $instance[ 's_flickr_noi' ] ) ? 6 : apply_filters( 'widget_s_flickr_noi', $instance[ 's_flickr_noi' ] );
		$s_flickr_tou    = empty( $instance[ 's_flickr_tou' ] ) ? 'user' : apply_filters( 'widget_s_flickr_tou', $instance[ 's_flickr_tou' ] );
		
		if( $s_flickr_tou == 'user' ) {
			$url = 'http://www.flickr.com/badge_code_v2.gne?count=' . $s_flickr_noi . '&display=latest&size=s&layout=v&source=' . $s_flickr_tou . '&user=' . $s_flickr_choice;
		} else if( $s_flickr_tou == 'all_tag' ) {
			$url = 'http://www.flickr.com/badge_code_v2.gne?count=' . $s_flickr_noi . '&display=latest&size=s&layout=v&source=' . $s_flickr_tou . '&tag=' . $s_flickr_choice;
		}
		
		$html = file_get_contents( $url );
		$matched = preg_match_all( '|<a.*?href=[\'"](.*?)[\'"].*?>.*?<img.*?src=[\'"](.*?)[\'"].*?><.*?a>|i', $html, $imgs );
		
		if( $matched > 0 ) {
			
			if( $s_flickr_title != '' ) {
				echo $before_title . $s_flickr_title . $after_title;
				echo '<span class="underline clearfix">&nbsp;</span>';
			};
			
			echo '<div class="sidenews clearfix">';
			$ci = 1;
			while( $ci <= $matched ) {
				echo '<a href="' . $imgs[ 1 ][ $ci - 1 ] . '" title="">';
				echo '<img class="flickr" src="' . $imgs[ 2 ][ $ci - 1 ] . '" alt="" width="75" height="75" />';
				echo '</a>';
				$ci ++;
			}
			echo '</div>';
		}
		
		echo $after_widget;
		
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_flickr_title' ]  = strip_tags( $new_instance[ 's_flickr_title' ] );
		$instance[ 's_flickr_choice' ] = strip_tags( $new_instance[ 's_flickr_choice' ] );
		$instance[ 's_flickr_noi' ]    = strip_tags( $new_instance[ 's_flickr_noi' ] );
		$instance[ 's_flickr_tou' ]    = strip_tags( $new_instance[ 's_flickr_tou' ] );
 
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_flickr_title' => '', 's_flickr_choice' => '', 's_flickr_noi' => '', 's_flickr_tou' => '' ) );
		$s_flickr_title  = strip_tags( $instance[ 's_flickr_title' ] );
		$s_flickr_choice = strip_tags( $instance[ 's_flickr_choice' ] );
		$s_flickr_noi    = strip_tags( $instance[ 's_flickr_noi' ] );
		$s_flickr_tou    = strip_tags( $instance[ 's_flickr_tou' ] );
?>

<p>
<label for="<?php echo $this->get_field_id( 's_flickr_title' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_flickr_title' ); ?>" name="<?php echo $this->get_field_name( 's_flickr_title' ); ?>" type="text" value="<?php echo esc_attr( $s_flickr_title ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_flickr_tou' ); ?>">
Show photos by user or tag(s)? 
</label>
<select class="widefat" id="<?php echo $this->get_field_id( 's_flickr_tou' ); ?>" name="<?php echo $this->get_field_name( 's_flickr_tou' ); ?>">
	<?php if( $s_flickr_tou == 'user' ) { ?>
    <option value="user" selected="selected"> - By user - </option>
    <option value="all_tag"> - By tag(s) - </option>
    <?php
    } else if( $s_flickr_tou == 'all_tag' ) {
    ?>
    <option value="user"> - By user - </option>
    <option value="all_tag" selected="selected"> - By tag(s) - </option>
    <?php
    } else {
    ?>
    <option value="user" selected="selected"> - By user - </option>
    <option value="all_tag"> - By tag(s) - </option>
    <?php
    }
    ?>
</select>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_flickr_choice' ); ?>">
If your choice was 'By tag(s)' - enter a tag or comma separated tags. Otherwise enter Flickr user ID (something like '14897087@N04'. Note: it's not a Flickr username!)
<input class="widefat" id="<?php echo $this->get_field_id( 's_flickr_choice' ); ?>" name="<?php echo $this->get_field_name( 's_flickr_choice' ); ?>" type="text" value="<?php echo esc_attr( $s_flickr_choice ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_flickr_noi' ); ?>">
Number of Flickr thumbs to show: 
<input id="<?php echo $this->get_field_id( 's_flickr_noi' ); ?>" name="<?php echo $this->get_field_name( 's_flickr_noi' ); ?>" type="text" size="3" value="<?php echo esc_attr( $s_flickr_noi ); ?>" />
</label>
</p>
            
<?php
	}
}
register_widget( 'SOFA_Flickr' );

// SOFA TAGS
class Sofa_Tags extends WP_Widget {
	function Sofa_Tags() {
		$widget_ops = array( 'classname' => 'widget_sofa_tags', 'description' => 'Display advanced tag cloud.' );
		$this->WP_Widget( 'sofa_tags', 'SOFA Tags', $widget_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
 
		echo $before_widget;
		
		$s_tags_title = empty( $instance[ 's_tags_title' ] ) ? __( "Tag Cloud", "sofa_suppastore" ) : apply_filters( 'widget_s_tags_title', $instance[ 's_tags_title' ] );
		$s_tags_numbr = empty( $instance[ 's_tags_numbr' ] ) ? 45 : apply_filters( 'widget_s_tags_numbr', $instance[ 's_tags_numbr' ] );

		if( $s_tags_title != ''  ) {
			echo $before_title . $s_tags_title . $after_title;
			echo '<span class="underline clearfix">&nbsp;</span>';
		}
		echo '<div class="sidenews clearfix">';
		$args = array(
			'smallest'                  => 100, 
			'largest'                   => 100,
			'unit'                      => '%', 
			'number'                    => intval( $s_tags_numbr ),  
			'format'                    => 'array',
			'separator'                 => ' &middot; ',
			'orderby'                   => 'name', 
			'order'                     => 'ASC',
			'exclude'                   => NULL, 
			'include'                   => NULL, 
			'topic_count_text_callback' => 'default_topic_count_text',
			'link'                      => 'view', 
			'taxonomy'                  => 'post_tag', 
			'echo'                      => false );
			
		$output_tags = wp_tag_cloud( $args );
		
		foreach( $output_tags as $t_bone ) {
			$match_val = 0;
			preg_match( "(<a.*?title=[\"'](.*?)[\"'].*?a>)i", $t_bone, $match );
			if( $match ) {
				$match_arr = explode( ' ', $match[ 1 ] );
				$match_val = $match_arr[ 0 ];
			}
			$t_bone = preg_replace( '#(<a.*?>)(.*?)(</a>)#', '$1$2 (' . $match_val . ')$3', $t_bone );
			echo '<span class="ptag">' . $t_bone . '</span>';
		}
		echo '</div>';
		echo $after_widget;
		
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_tags_title' ] = strip_tags( $new_instance[ 's_tags_title' ] );
		$instance[ 's_tags_numbr' ] = strip_tags( $new_instance[ 's_tags_numbr' ] );
 
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_tags_title' => '', 's_tags_numbr' => '' ) );
		$s_tags_title = strip_tags( $instance[ 's_tags_title' ] );
		$s_tags_numbr = strip_tags( $instance[ 's_tags_numbr' ] );
?>

<p>
<label for="<?php echo $this->get_field_id( 's_tags_title' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_tags_title' ); ?>" name="<?php echo $this->get_field_name( 's_tags_title' ); ?>" type="text" value="<?php echo esc_attr( $s_tags_title ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_tags_numbr' ); ?>">
Number of Tags to show (use 0 for all): 
<input id="<?php echo $this->get_field_id( 's_tags_numbr' ); ?>" name="<?php echo $this->get_field_name( 's_tags_numbr' ); ?>" type="text" size="3" value="<?php echo esc_attr( $s_tags_numbr ); ?>" />
</label>
</p>
            
<?php
	}
}
register_widget( 'Sofa_Tags' );

// RECENT POSTS 
class SOFA_RecentPosts extends WP_Widget {
	function SOFA_RecentPosts() {
		$widget_ops = array( 'classname' => 'widget_sofa_recentposts', 'description' => 'Display N number of recent Posts.' );
		$this->WP_Widget( 'sofa_recentposts', 'SOFA Recent Posts', $widget_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );

		echo $before_widget;
		
		$s_recentposts_title  = empty( $instance[ 's_recentposts_title' ] ) ? '' : apply_filters( 'widget_s_recentposts_title', $instance[ 's_recentposts_title' ] );
		$s_recentposts_sort   = empty( $instance[ 's_recentposts_sort' ] ) ? 'DESC' : apply_filters( 'widget_s_recentposts_sort', $instance[ 's_recentposts_sort' ] );
		$s_recentposts_number = empty( $instance[ 's_recentposts_number' ] ) ? 5 : apply_filters( 'widget_s_recentposts_number', $instance[ 's_recentposts_number' ] );
		$s_recentposts_trim   = empty( $instance[ 's_recentposts_trim' ] ) ? 0 : apply_filters( 'widget_s_recentposts_trim', $instance[ 's_recentposts_trim' ] );
		$s_recentposts_img    = empty( $instance[ 's_recentposts_img' ] ) ? 'no' : apply_filters( 'widget_s_recentposts_img', $instance[ 's_recentposts_img' ] );
		$s_recentposts_cat    = empty( $instance[ 's_recentposts_cat' ] ) ? '' : apply_filters( 'widget_s_recentposts_cat', $instance[ 's_recentposts_cat' ] );

		if( $s_recentposts_title != '' ) {
			echo $before_title . $s_recentposts_title . $after_title;
			echo '<span class="underline clearfix">&nbsp;</span>';
		};
		
		$appx_cats = '';
		if( strlen( $s_recentposts_cat >= 1 ) ) $appx_cats = '&cat=' . $s_recentposts_cat;
		query_posts( 'order=' . $s_recentposts_sort . '&showposts=' . $s_recentposts_number . $appx_cats );
		
		if( have_posts() ) : while( have_posts() ) : the_post();
		
        echo '<div class="sidenews castshadow clearfix">';

		$this_id = intval( get_the_ID() );
		$rp_perma = get_permalink( $this_id );
		
		if( $s_recentposts_img == 'yes' ) {
			/* extract image - if any */
			$attFilez =& get_children( 'post_type=attachment&post_mime_type=image&orderby=menu_order&order=ASC&post_parent=' . $this_id );
			$arrKF = array_keys( $attFilez );
			if( $arrKF[ 0 ] ) {
				$rfp = wp_get_attachment_image_src( $arrKF[ 0 ], 'miniature' );
				$img_saved = '<img src="' . $rfp[ 0 ] . '" class="size-miniature alignleft" alt="" />';
			}
			/* end extract image */
			if( $s_recentposts_trim > 0 ) {
				echo '<h4><a href="' . $rp_perma . '" rel="nofollow">' . get_the_title() . '</a></h4>';
				echo '<p>' . $img_saved . '<span class="small">' . get_the_time( get_option( 'date_format' ) ) . '</span> &bull; ' . trim_the_content( get_the_excerpt(), __( "...READ MORE", "sofa_suppastore" ), $rp_perma, $s_recentposts_trim ) . '</p>'; } else {
				echo '<p><span class="small">' . get_the_time( get_option( 'date_format' ) ) . '</span> &bull; ' . $img_saved . ''  . '<a href="' . $rp_perma . '" rel="nofollow">' . get_the_title() . '</a></p>';
			}
		} else {
			if( $s_recentposts_trim > 0 ) {
				echo '<h4><a href="' . $rp_perma . '" rel="nofollow">' . get_the_title() . '</a></h4>';
				echo '<p><span class="small">' . get_the_time( get_option( 'date_format' ) ) . '</span> &bull; ' . trim_the_content( get_the_excerpt(), __( "...READ MORE", "sofa_suppastore" ), $rp_perma, $s_recentposts_trim ) . '</p>';
			} else {
				echo '<p><span class="small">' . get_the_time( get_option( 'date_format' ) ) . '</span> &bull; <a href="' . $rp_perma . '" rel="nofollow">' . get_the_title() . '</a></p>';
			}
		}

		echo '</div>';

		endwhile;
		
		wp_reset_query();

		else :
		
		echo '<div class="sidenews clearfix"><p>';
		echo __( "No Recent Posts found!", "sofa_suppastore" );
		echo '</p></div>';
		
		endif;
		
		echo $after_widget;
		
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_recentposts_title' ]  = strip_tags( $new_instance[ 's_recentposts_title' ] );
		$instance[ 's_recentposts_sort' ]   = strip_tags( $new_instance[ 's_recentposts_sort' ] );
		$instance[ 's_recentposts_number' ] = strip_tags( $new_instance[ 's_recentposts_number' ] );
		$instance[ 's_recentposts_trim' ]   = strip_tags( $new_instance[ 's_recentposts_trim' ] );
		$instance[ 's_recentposts_img' ]    = strip_tags( $new_instance[ 's_recentposts_img' ] );
		$instance[ 's_recentposts_cat' ]    = strip_tags( $new_instance[ 's_recentposts_cat' ] );
 
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_recentposts_title' => '', 's_recentposts_sort' => '', 's_recentposts_number' => '', 's_recentposts_trim' => '', 's_recentposts_img' => '', 's_recentposts_cat' => '' ) );
		$s_recentposts_title  = strip_tags( $instance[ 's_recentposts_title' ] );
		$s_recentposts_sort   = strip_tags( $instance[ 's_recentposts_sort' ] );
		$s_recentposts_number = strip_tags( $instance[ 's_recentposts_number' ] );
		$s_recentposts_trim   = intval( $instance[ 's_recentposts_trim' ] );
		if( $s_recentposts_trim < 0 ) $s_recentposts_trim = 0;
		$s_recentposts_img    = $instance[ 's_recentposts_img' ];
		$s_recentposts_cat    = $instance[ 's_recentposts_cat' ];
?>

<p>
<label for="<?php echo $this->get_field_id( 's_recentposts_title' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_recentposts_title' ); ?>" name="<?php echo $this->get_field_name( 's_recentposts_title' ); ?>" type="text" value="<?php echo esc_attr( $s_recentposts_title ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_recentposts_sort' ); ?>">
Sort by: 
</label>
<select class="widefat" id="<?php echo $this->get_field_id( 's_recentposts_sort' ); ?>" name="<?php echo $this->get_field_name( 's_recentposts_sort' ); ?>">
	<?php if( $s_recentposts_sort == 'ASC' ) { ?>
    <option value="ASC" selected="selected"> - Ascending - </option>
    <option value="DESC"> - Descending - </option>
    <?php
    } else if( $s_recentposts_sort == 'DESC' ) {
    ?>
    <option value="ASC"> - Ascending - </option>
    <option value="DESC" selected="selected"> - Descending - </option>
    <?php
    } else {
    ?>
    <option value="ASC"> - Ascending - </option>
    <option value="DESC" selected="selected"> - Descending - </option>
    <?php
    }
    ?>
</select>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_recentposts_number' ); ?>">
Number of Recent Posts to show: 
<input id="<?php echo $this->get_field_id( 's_recentposts_number' ); ?>" name="<?php echo $this->get_field_name( 's_recentposts_number' ); ?>" type="text" size="3" value="<?php echo esc_attr( $s_recentposts_number ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_recentposts_trim' ); ?>">
Trim Post intro/summary to N number of words: 
<input id="<?php echo $this->get_field_id( 's_recentposts_trim' ); ?>" name="<?php echo $this->get_field_name( 's_recentposts_trim' ); ?>" type="text" size="3" value="<?php echo esc_attr( $s_recentposts_trim ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_recentposts_img' ); ?>">
Display mini image? 
</label>
<select class="widefat" id="<?php echo $this->get_field_id( 's_recentposts_img' ); ?>" name="<?php echo $this->get_field_name( 's_recentposts_img' ); ?>">
	<?php if( $s_recentposts_img == 'yes' ) { ?>
    <option value="yes" selected="selected"> - YES - </option>
    <option value="no"> - NO - </option>
    <?php
    } else if( $s_recentposts_sort == 'no' ) {
    ?>
    <option value="yes"> - YES - </option>
    <option value="no" selected="selected"> - NO - </option>
    <?php
    } else {
    ?>
    <option value="yes"> - YES - </option>
    <option value="no" selected="selected"> - NO - </option>
    <?php
    }
    ?>
</select>
</p>

<p>

<label for="<?php echo $this->get_field_id( 's_recentposts_cat' ); ?>">
Show posts from category (comma separate category IDs if more than one, for ex. 0, 7, 16): 
<input class="widefat" id="<?php echo $this->get_field_id( 's_recentposts_cat' ); ?>" name="<?php echo $this->get_field_name( 's_recentposts_cat' ); ?>" type="text" value="<?php echo esc_attr( $s_recentposts_cat ); ?>" />
</label>
</p>
            
<?php
	}
}
register_widget( 'SOFA_RecentPosts' );

// RECENT COMMENTS 
class SOFA_RecentComments extends WP_Widget {
	function SOFA_RecentComments() {
		$widget_ops = array( 'classname' => 'widget_sofa_recentcomments', 'description' => 'Display N number of recent comments.' );
		$this->WP_Widget( 'sofa_recentcomments', 'SOFA Recent Comments', $widget_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
 
		echo $before_widget;
		
		$s_recentcomments_title = empty( $instance[ 's_recentcomments_title' ] ) ? '' : apply_filters( 'widget_s_recentcomments_title', $instance[ 's_recentcomments_title' ] );
		$s_recentcomments_number = empty( $instance[ 's_recentcomments_number' ] ) ? 5 : apply_filters( 'widget_s_recentcomments_number', $instance[ 's_recentcomments_number' ] );
		
		if( $s_recentcomments_title != '' ) {
			echo $before_title . $s_recentcomments_title . $after_title;
			echo '<span class="underline clearfix">&nbsp;</span>';
		};

		global $wpdb;
		$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_date, comment_approved, comment_type, comment_author_url, SUBSTRING(comment_content,1,120) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT $s_recentcomments_number";
		$commentz = $wpdb->get_results( $sql );
		
		if( $commentz ) {

			foreach( $commentz as $comm ) {
				echo '<div class="sidenews castshadow clearfix">';
				echo '<span class="newsinfo small clearfix">' . mysql2date( get_option( 'date_format' ), $comm->comment_date ) . ' &bull; ' . __( "By", "sofa_suppastore" ) . $comm->comment_author . '</span>';
				echo '<p><a href="' . get_permalink( $comm->ID ) . '#comment-' . $comm->comment_ID . '" title="' . $comm->post_title . '">' . strip_tags( $comm->com_excerpt ) . '...</a></p>';
				echo '</div>';
			}

		} else {
			echo '<div class="sidenews clearfix"><p class="smallfoot">';
			echo __( "No Recent Reviews found!", "sofa_suppastore" );
			echo '</p></div>';
		}
		
		echo $after_widget;
		
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_recentcomments_title' ] = strip_tags( $new_instance[ 's_recentcomments_title' ] );
		$instance[ 's_recentcomments_number' ] = strip_tags( $new_instance[ 's_recentcomments_number' ] );
 
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_recentcomments_title' => '', 's_recentcomments_number' => '' ) );
		$s_recentcomments_title = strip_tags( $instance[ 's_recentcomments_title' ] );
		$s_recentcomments_number = strip_tags( $instance[ 's_recentcomments_number' ] );
?>

<p>
<label for="<?php echo $this->get_field_id( 's_recentcomments_title' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_recentcomments_title' ); ?>" name="<?php echo $this->get_field_name( 's_recentcomments_title' ); ?>" type="text" value="<?php echo esc_attr( $s_recentcomments_title ); ?>" />
</label>
</p>

<p>
<label for="<?php echo $this->get_field_id( 's_recentcomments_number' ); ?>">
Number of Recent Reviews to show: 
<input id="<?php echo $this->get_field_id( 's_recentcomments_number' ); ?>" name="<?php echo $this->get_field_name( 's_recentcomments_number' ); ?>" type="text" size="3" value="<?php echo esc_attr( $s_recentcomments_number ); ?>" />
</label>
</p>
            
<?php
	}
}
register_widget( 'SOFA_RecentComments' );

// GOOGLE MAPS 
class SOFA_Gmaps extends WP_Widget {
	function SOFA_Gmaps() {
		$widget_ops = array( 'classname' => 'widget_sofa_gmaps', 'description' => 'Display Google map in sidebar.' );
		$this->WP_Widget( 'sofa_gmaps', 'SOFA GoogleMaps', $widget_ops );
	}
 
	function widget( $args, $instance ) {
		extract( $args, EXTR_SKIP );
		
		// variables
		$s_gmaps_tit = empty( $instance[ 's_gmaps_tit' ] ) ? '' : apply_filters( 'widget_s_gmaps_tit', $instance[ 's_gmaps_tit' ] );
		$s_gmaps_txt = empty( $instance[ 's_gmaps_txt' ] ) ? '' : apply_filters( 'widget_s_gmaps_txt', $instance[ 's_gmaps_txt' ] );
		$s_gmaps_lat = empty( $instance[ 's_gmaps_lat' ] ) ? '' : apply_filters( 'widget_s_gmaps_lat', $instance[ 's_gmaps_lat' ] ); // latitude
		$s_gmaps_lng = empty( $instance[ 's_gmaps_lng' ] ) ? '' : apply_filters( 'widget_s_gmaps_lng', $instance[ 's_gmaps_lng' ] ); // longitude
		$s_gmaps_zom = empty( $instance[ 's_gmaps_zom' ] ) ? '5' : apply_filters( 'widget_s_gmaps_zom', $instance[ 's_gmaps_zom' ] ); // zoom level 1-19
		$s_gmaps_typ = empty( $instance[ 's_gmaps_typ' ] ) ? 'ROADMAP' : apply_filters( 'widget_s_gmaps_typ', $instance[ 's_gmaps_typ' ] ); // type ROADMAP, SATELLITE, HYBRID, TERRAIN
		$s_gmaps_dir = empty( $instance[ 's_gmaps_dir' ] ) ? '' : apply_filters( 'widget_s_gmaps_dir', $instance[ 's_gmaps_dir' ] ); // directions aka address
		$s_gmaps_con = empty( $instance[ 's_gmaps_con' ] ) ? '' : apply_filters( 'widget_s_gmaps_con', $instance[ 's_gmaps_con' ] ); // content
		
		$s_gmaps_con = str_replace( '&lt;', '<', $s_gmaps_con );
		$s_gmaps_con = str_replace( '&gt;', '>', $s_gmaps_con );
		$s_gmaps_con = mysql_escape_string( $s_gmaps_con );
		
		$required_lat = $s_gmaps_lat;
		$required_lng = $s_gmaps_lng;
				
		echo $before_widget;

		if( $s_gmaps_tit != '' ) {
			echo $before_title . $s_gmaps_tit . $after_title;
			echo '<span class="underline clearfix">&nbsp;</span>';
		};
		
		if( $s_gmaps_txt != '' ) echo do_shortcode( wpautop( stripslashes( $s_gmaps_txt ), $br = 1 ) );
		
		// display gmap
		if( strlen( $required_lat ) < 3 && strlen( $required_lng ) < 3 ) {
			if( !function_exists( 'file_get_contents' ) ) {
				echo '<div class="sidenews clearfix"><p class="smallfoot">"file_get_contents" has been disabled by your hosting provider!</p></div>';
			} else {
				$map_api_call = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode( $s_gmaps_dir ) . '&sensor=false';
				$map_api_response = file_get_contents( $map_api_call );
				
				// json_decode available only for PHP 5.2 +
				if( !function_exists( 'json_decode' ) ) {
					$json = $map_api_response;
					$comm = false;
					$outh = '$conv_json=';
					for( $i = 0; $i < strlen( $json ); $i ++ ) {
						if( !$comm ) {
							if( $json[ $i ] == '{' ) $outh .= ' array(';
							else if( $json[ $i ] == '[' || $json[ $i ] == ']' ) $outh .= '';
							else if( $json[ $i ] == '}' ) $outh .= ')';
							else if( $json[ $i ] == ':' ) $outh .= '=>';
							else $outh .= $json[ $i ];           
						}
						else $outh .= $json[ $i ];
						if( $json[ $i ] == '"' ) $comm = !$comm;
					}
					// eval( $outh . ';' );
					$outh = str_replace( array( '[',      ']',      '{', '}' ), array( '\u005B', '\u005D', '[', ']' ), $outh );
					$required_lat = $conv_json[ 'results' ][ 'geometry' ][ 'location' ][ 'lat' ];
					$required_lng = $conv_json[ 'results' ][ 'geometry' ][ 'location' ][ 'lng' ];
				} else {
					// do regular
					$json = $map_api_response;
					$json = preg_replace( '/,\s*([\]}])/m', '$1', $json );
					$json_obj = json_decode( utf8_encode( $json ), true );
					$required_lat = $json_obj[ 'results' ][ 0 ][ 'geometry' ][ 'location' ][ 'lat' ];
					$required_lng = $json_obj[ 'results' ][ 0 ][ 'geometry' ][ 'location' ][ 'lng' ];
				}
			}
		}
		
		if( $required_lat != '' && $required_lng != '' ) {
		?>
        
		<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
        <script type="text/javascript">

            function makeMap() {
				
                var latlng = new google.maps.LatLng( <?php echo $required_lat; ?>, <?php echo $required_lng; ?> );
                
                var myOptions = {
                    zoom: <?php echo $s_gmaps_zom; ?>,
                    center: latlng,
                    mapTypeControl: true,
                    mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU },
                    navigationControl: true,
                    navigationControlOptions: { style: google.maps.NavigationControlStyle.SMALL },
                    mapTypeId: google.maps.MapTypeId.<?php echo $s_gmaps_typ; ?>
                };
				
                var map = new google.maps.Map( document.getElementById( "showgmap" ), myOptions );
                
                var contentString = "<?php echo urlencode( '<p class="smallfoot">' . $s_gmaps_dir . '</p><p class="smallfoot">' . $s_gmaps_con . '</p>' ); ?>";
				var dec_contentString = decodeURIComponent( contentString );
                var infowindow = new google.maps.InfoWindow( {
                    content: dec_contentString.replace( /\+/g, ' ' )
                } );
                
                var marker = new google.maps.Marker( {
                    position: latlng,
                    map: map,
                    title: ""
                } );
                
                google.maps.event.addListener( marker, "click", function() {
                  infowindow.open( map, marker );
                } );
            }
			
            window.onload = makeMap;

        </script>
        
        <div id="showgmap">&nbsp;</div>

		<?php
		}
		
		echo $after_widget;
		
	}
 
	function update( $new_instance, $old_instance ) {
		$instance = $old_instance;
		$instance[ 's_gmaps_tit' ] = strip_tags( $new_instance[ 's_gmaps_tit' ] );
		$instance[ 's_gmaps_txt' ] = $new_instance[ 's_gmaps_txt' ];
		$instance[ 's_gmaps_lat' ] = strip_tags( $new_instance[ 's_gmaps_lat' ] );
		$instance[ 's_gmaps_lng' ] = strip_tags( $new_instance[ 's_gmaps_lng' ] );
		$instance[ 's_gmaps_zom' ] = strip_tags( $new_instance[ 's_gmaps_zom' ] );
		$instance[ 's_gmaps_typ' ] = strip_tags( $new_instance[ 's_gmaps_typ' ] );
		$instance[ 's_gmaps_dir' ] = strip_tags( $new_instance[ 's_gmaps_dir' ] );
		$instance[ 's_gmaps_con' ] = strip_tags( $new_instance[ 's_gmaps_con' ] );
 
		return $instance;
	}
 
	function form( $instance ) {
		$instance = wp_parse_args( ( array ) $instance, array( 's_gmaps_tit' => '', 's_gmaps_txt' => '', 's_gmaps_lat' => '', 's_gmaps_lng' => '', 's_gmaps_zom' => '', 's_gmaps_typ' => '', 's_gmaps_dir' => '', 's_gmaps_con' => '' ) );
		$s_gmaps_tit = strip_tags( $instance[ 's_gmaps_tit' ] );
		$s_gmaps_txt = $instance[ 's_gmaps_txt' ];
		$s_gmaps_lat = strip_tags( $instance[ 's_gmaps_lat' ] );
		$s_gmaps_lng = strip_tags( $instance[ 's_gmaps_lng' ] );
		$s_gmaps_zom = strip_tags( $instance[ 's_gmaps_zom' ] );
		$s_gmaps_typ = strip_tags( $instance[ 's_gmaps_typ' ] );
		$s_gmaps_dir = strip_tags( $instance[ 's_gmaps_dir' ] );
		$s_gmaps_con = strip_tags( $instance[ 's_gmaps_con' ] );
?>

<p>
This Widget will add GoogleMap to any Widget ready area.
</p>
<p>
<label for="<?php echo $this->get_field_id( 's_gmaps_tit' ); ?>">
Title: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_gmaps_tit' ); ?>" name="<?php echo $this->get_field_name( 's_gmaps_tit' ); ?>" type="text" value="<?php echo esc_attr( $s_gmaps_tit ); ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 's_gmaps_txt' ); ?>">
Text above the map (HTML is OK!):
</label>
<textarea class="widefat" rows="5" cols="50" id="<?php echo $this->get_field_id( 's_gmaps_txt' ); ?>" name="<?php echo $this->get_field_name( 's_gmaps_txt' ); ?>" type="text" value="<?php echo esc_attr( $s_gmaps_txt ); ?>"><?php echo $s_gmaps_txt; ?></textarea>
</p>
<p>
<label for="<?php echo $this->get_field_id( 's_gmaps_lat' ); ?>">
Latitude (leave empty if unknown, it'll be extracted from address): 
<input class="widefat" id="<?php echo $this->get_field_id( 's_gmaps_lat' ); ?>" name="<?php echo $this->get_field_name( 's_gmaps_lat' ); ?>" type="text" value="<?php echo esc_attr( $s_gmaps_lat ); ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 's_gmaps_lng' ); ?>">
Longitude (leave empty if unknown, it'll be extracted from address): 
<input class="widefat" id="<?php echo $this->get_field_id( 's_gmaps_lng' ); ?>" name="<?php echo $this->get_field_name( 's_gmaps_lng' ); ?>" type="text" value="<?php echo esc_attr( $s_gmaps_lng ); ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 's_gmaps_zom' ); ?>">
Zoom level: 
</label>
<select class="widefat" id="<?php echo $this->get_field_id( 's_gmaps_zom' ); ?>" name="<?php echo $this->get_field_name( 's_gmaps_zom' ); ?>">
	<?php
	$levels_selected = esc_attr( $s_gmaps_zom );
	$levels_start = 1;
	$levels_range = 19;
	while( $levels_start <= $levels_range ) {
		if( $levels_start == $levels_selected ) echo '<option value="' . $levels_start . '" selected="selected"> - ' . $levels_start . ' - </option>';
    	else echo '<option value="' . $levels_start . '"> - ' . $levels_start . ' - </option>';
		$levels_start ++;
    }
    ?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id( 's_gmaps_typ' ); ?>">
Map type: 
</label>
<select class="widefat" id="<?php echo $this->get_field_id( 's_gmaps_typ' ); ?>" name="<?php echo $this->get_field_name( 's_gmaps_typ' ); ?>">
	<?php
	// types
	$map_types_selected = esc_attr( $s_gmaps_typ );
    $map_types_arr = array( 'ROADMAP', 'SATELLITE', 'HYBRID', 'TERRAIN' );
	$map_types_arr_length = count( $map_types_arr );
	$map_types_arr_iterat = 0;
	while( $map_types_arr_iterat < $map_types_arr_length ) {
		if( $map_types_arr[ $map_types_arr_iterat ] == $map_types_selected ) echo '<option value="' . $map_types_arr[ $map_types_arr_iterat ] . '" selected="selected"> - ' . $map_types_arr[ $map_types_arr_iterat ] . ' - </option>';
		else echo '<option value="' . $map_types_arr[ $map_types_arr_iterat ] . '"> - ' . $map_types_arr[ $map_types_arr_iterat ] . ' - </option>';
		$map_types_arr_iterat ++;
	}
    ?>
</select>
</p> 
<p>
<label for="<?php echo $this->get_field_id( 's_gmaps_dir' ); ?>">
Address to pin: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_gmaps_dir' ); ?>" name="<?php echo $this->get_field_name( 's_gmaps_dir' ); ?>" type="text" value="<?php echo esc_attr( $s_gmaps_dir ); ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 's_gmaps_con' ); ?>">
Additional info in Bubble: 
<input class="widefat" id="<?php echo $this->get_field_id( 's_gmaps_con' ); ?>" name="<?php echo $this->get_field_name( 's_gmaps_con' ); ?>" type="text" value="<?php echo esc_attr( $s_gmaps_con ); ?>" />
</label>
</p> 
<?php
	}
}
register_widget( 'SOFA_Gmaps' );